package com.iscas.tech.controller;

import com.iscas.tech.entity.AtMdbusyValue;
import com.iscas.tech.param.AtMdbusyValuePageParam;
import com.iscas.tech.service.AtMdbusyValueService;
import com.iscas.tech.vo.AtMdbusyValueQueryVo;
import io.geekidea.springbootplus.framework.common.api.ApiCode;
import io.geekidea.springbootplus.framework.common.api.ApiResult;
import io.geekidea.springbootplus.framework.common.controller.BaseController;
import io.geekidea.springbootplus.framework.pagination.Paging;
import io.geekidea.springbootplus.framework.shiro.util.LoginUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 模块业务值对应表 控制器
 *
 * @author yangyi
 * @since 2020-10-26
 */
@Slf4j
@RestController
@RequestMapping("/business")
@Api(value = "模块业务值对应表API", tags = {"模块业务值对应表"})
public class AtMdbusyValueController extends BaseController {

    @Autowired
    private AtMdbusyValueService atMdbusyValueService;

    /**
     * 添加模块业务值对应表
     */
    @PostMapping("/add")
    @ApiOperation(value = "添加模块业务值对应表", response = ApiResult.class)
    public ApiResult<Boolean> addAtMdbusyValue(AtMdbusyValue atMdbusyValue) throws Exception {
        if (LoginUtil.getUserId() == null) {
            return ApiResult.fail(ApiCode.UNAUTHORIZED);
        }
        atMdbusyValue.setCreatetitle(LoginUtil.getUserId().intValue());
        boolean flag = atMdbusyValueService.saveAtMdbusyValue(atMdbusyValue);
        return ApiResult.result(flag);
    }

    /**
     * 修改模块业务值对应表
     */
    @PostMapping("/update")
    @ApiOperation(value = "修改模块业务值对应表", response = ApiResult.class)
    public ApiResult<Boolean> updateAtMdbusyValue(AtMdbusyValue atMdbusyValue) throws Exception {
        boolean flag = atMdbusyValueService.updateAtMdbusyValue(atMdbusyValue);
        return ApiResult.result(flag);
    }

    /**
     * 删除模块业务值对应表
     */
    @RequestMapping(value = "delete" ,produces = "application/json; charset=utf-8")
    @ApiOperation(value = "删除模块业务值对应表", response = ApiResult.class)
    public ApiResult<Boolean> deleteAtMdbusyValue(String ids) throws Exception {
        String idArr[] = ids.split(",");
        for (String id : idArr) {
            atMdbusyValueService.deleteAtMdbusyValue(Long.parseLong(id));
        }

        return ApiResult.ok();
    }

    /**
     * 获取模块业务值对应表详情
     */
    @RequestMapping(value = "info" ,produces = "application/json; charset=utf-8")
    @ApiOperation(value = "模块业务值对应表详情", response = AtMdbusyValue.class)
    public ApiResult<AtMdbusyValue> getAtMdbusyValue(Long id) throws Exception {
        AtMdbusyValue atMdbusyValue = atMdbusyValueService.getById(id);
        return ApiResult.ok(atMdbusyValue);
    }

    /**
     * 模块业务值对应表分页列表
     */
    @PostMapping("/getPageList")
    @ApiOperation(value = "模块业务值对应表分页列表", response = AtMdbusyValue.class)
    public ApiResult<Paging<AtMdbusyValueQueryVo>> getAtMdbusyValuePageList(AtMdbusyValuePageParam atMdbusyValuePageParam) throws Exception {
        Paging<AtMdbusyValueQueryVo> paging = atMdbusyValueService.getAtMdbusyValuePageList(atMdbusyValuePageParam);
        return ApiResult.ok(paging);
    }

}

